﻿using IntoStationSystem.ViewModels;
using System;
using System.Linq;
using System.Windows.Controls;

namespace IntoStationSystem.Views
{
    /// <summary>
    /// LeakageTester.xaml 的交互逻辑
    /// </summary>
    public partial class LeakageView : UserControl
    {
        public LeakageView()
        {
            InitializeComponent();
            this.DataContext = Locator.Instance.Leakage;
        }

        //DataPos pos => Locator.Instance.Service.PlcMapping.DataMapping.DataPos.Where(o => o.Desc == "Leakage").FirstOrDefault();

        private void ActionDown_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            int bitOffset = Convert.ToInt32((sender as Button).CommandParameter);
            //Locator.Instance.Service.WriteBool(pos.Offset, bitOffset, true);
        }

        private void ActionUp_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            int bitOffset = Convert.ToInt32((sender as Button).CommandParameter);
            //Locator.Instance.Service.WriteBool(pos.Offset, bitOffset, false);
        }

        private void SetProgramDown_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            byte[] datas = S7.Net.Types.Int.ToByteArray((short)Locator.Instance.Leakage.ProgramNum);
            //Locator.Instance.Service.WriteData(pos.Offset + 2, datas);
        }

        private void SetProgramUp_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            Locator.Instance.Leakage.ProgramNum = Convert.ToInt32((sender as TextBox).Text);
        }
    }
}
